package kamkor.ann.namerecog.network.parser

import scala.xml._
import scala.collection.mutable.HashMap

import java.io.File

/** <p>Parses xml file containing input and output mappings, and builds inputConversionMap 
 *  and outputConversionMap.</p>
 *   
 * @author kamkor
 *
 */
class ConversionMapXmlParser(file: File) {
	/** inputConversionMap("a" -> 0, "b" -> 1) etc. */
	val inputConversionMap = new HashMap[Char, Int]()
	
	/** outputConversionMap(0 -> "Polish", 1 -> "Russian") etc. */
	val outputConversionMap = new HashMap[Int, String]()
	
	private val rootNode = XML.loadFile(file)
	for (inputMapNode <- rootNode \ "inputMappings" \ "map") {
		val key = (inputMapNode \ "@key").text
		val value = (inputMapNode \ "@value").text.toInt
		inputConversionMap += key(0) -> value
	}		
	for (outputMapNode <- rootNode \ "outputMappings" \ "map") {
		val key = (outputMapNode \ "@key").text.toInt
		val value = (outputMapNode \ "@value").text
		outputConversionMap += key -> value
	}
}